/*
2021-8-15
https://www.acwing.com/problem/content/1115/
*/ 
dfs

#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=25;
char g[N][N];
bool st[N][N];
int n,m;
int sx,sy;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int dfs(int x,int y)
{
    int res=1;
    st[x][y]=true;
    for(int i=0;i<4;i++)
    {
        int a=x+dx[i],b=y+dy[i];
        if(a<0 || a>=n || b<0 || b>=m) continue;
        if(st[a][b]) continue;
        if(g[a][b]=='#') continue;
        res+=dfs(a,b);
    }
    return res;
}

int main()
{
    while(cin>>m>>n,n||m)
    {
        memset(st,false,sizeof st);
        for(int i=0;i<n;i++) 
        {
            cin>>g[i];
            for(int j=0;j<m;j++)
            {
                if(g[i][j]=='@')
                {
                    sx=i,sy=j;
                }
            }
        }
        cout<<dfs(sx,sy)<<endl;
    }
    return 0;
}

bfs

#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
typedef pair<int,int>PII;
const int N=25;
char g[N][N];
bool st[N][N];
PII q[N*N];
int n,m;
int sx,sy;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int bfs(int x,int y)
{
    st[x][y]=true;
    int hh=0,tt=0;
    q[0]={x,y};
    int res=0;
    while(hh<=tt)
    {
        auto t=q[hh++];
        res++;
        for(int i=0;i<4;i++)
        {
            int a=t.first+dx[i],b=t.second+dy[i];
            if(st[a][b]==true) continue;
            if(a<0 || a>=n || b<0 || b>=m) continue;
            if(g[a][b]=='#') continue;
            q[++tt]={a,b};
            st[a][b]=true;
        }
    }

    return res;
}

int main()
{
    while(cin>>m>>n,n||m)
    {
        memset(st,false,sizeof st);
        for(int i=0;i<n;i++) 
        {
            cin>>g[i];
            for(int j=0;j<m;j++)
            {
                if(g[i][j]=='@')
                {
                    sx=i,sy=j;
                }
            }
        }
        cout<<bfs(sx,sy)<<endl;
    }
    return 0;
}

